home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#) menus.c 12.1 95/05/09 SCOINC
- */
- /***************************************************************************
- *
- * Copyright (c) 1990-1993 The Santa Cruz Operation, Inc.
- *
- * All rights reserved. No part of this program or publication may be
- * reproduced, transmitted, transcribed, stored in a retrieval system,
- * or translated into any language or computer language, in any form or
- * by any means, electronic, mechanical, magnetic, optical, chemical,
- * biological, or otherwise, without the prior written permission of:
- *
- * The Santa Cruz Operation , Inc. (408) 425-7222
- * 400 Encinal St., Santa Cruz, California 95060 USA
- *
- **************************************************************************/
- /*
- * Modification History
- *
- * S003, 15-Sep-93, rickra
- * Create the function create_window_option_menu_bar.
- *
- * S002, 27-May-93, rickra
- * Took out all "seperate window" entries. This is now taken care
- * of in xsw.c as toggle button callbacks.....
- *
- * S001, 01-Jan-93, rickra
- * Added ascending/descending of PSMEM , PSIO, PSCPU
- *
- * S000, 30-Sep-92, rickra
- * Added copyright and modification history
- */
- #include <stdio.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Intrinsic.h>
- #include <X11/Shell.h>
- #include <X11/StringDefs.h>
- #include <Xm/Xm.h>
- #include <Xm/MainW.h>
- #include <Xm/DrawingA.h>
- #include <Xm/Separator.h>
- #include <Xm/ToggleB.h>
- #include <Xm/CascadeB.h>
- #include <Xm/RowColumn.h>
- #include <Xm/Label.h>
-
- #include "include/menus.h"
- #include "include/buttons.h"
- #include "include/resources.h"
- #include "include/xprocs.h"
- #include "include/sepwin.h"
-
- extern XColor colorAuxButtonOnForeground;;
- extern XColor colorAuxButtonOnBackground;;
- extern XColor colorAuxButtonOffForeground;;
- extern XColor colorAuxButtonOffBackground;;
-
- extern unsigned long foreground;
-
- extern Widget sub_menu_state_list[Max_sub_menu_buttons];
-
- extern char connect_to_server_string[];
- extern char disconnect_to_server_string[];
- extern char quit_string[];
-
-
- extern char font_Default_string[];
- extern char font_6x10_string[];
- extern char font_6x12_string[];
- extern char font_6x13_string[];
- extern char font_8x13_string[];
- extern char font_9x15_string[];
- extern char font_ibm10x20_string[];
-
- extern char general_help_string[];
- extern char option_help_string[];
- extern char known_help_string[];
-
- extern char increase_string1[];
- extern char decrease_string1[];
- extern char popup_string1[];
- extern char increase_string2[];
- extern char decrease_string2[];
- extern char popup_string2[];
- extern char increase_string3[];
- extern char decrease_string3[];
- extern char popup_string3[];
-
-
-
- char file_string[] = "File";
-
- void
- xs_create_menu_buttons (title, menu, menulist, nitems, dynamic_callback_data,
- callback_data)
- char *title;
- Widget menu;
- xs_menu_struct *menulist;
- int nitems;
- int dynamic_callback_data;
- struct ps_button_callback_struct *callback_data;
-
- {
-
- int i;
- WidgetList buttons;
- int separators = 0;
- char *help_string = "Help";
- Widget help_widget;
-
- Arg args[32];
- int argcount = 0;
-
- /*
- * Allocate a widget list to hold all button widgets.
- */
-
- buttons = (WidgetList) XtMalloc (nitems * sizeof (Widget));
-
- /*
- * If a title is given, create Label and Separator widgets.
- */
-
- if (title)
- {
-
- argcount = 0;
-
- XtCreateManagedWidget (title, xmLabelWidgetClass, menu,
- args, argcount);
-
- XtCreateManagedWidget ("separator", xmSeparatorWidgetClass,
- menu, args, argcount);
- }
-
- /*
- * Create an entry for each item in the menu.
- */
-
- for (i = 0; i < nitems; i++)
- {
-
- /*
- * A NULL name represents a separator.
- */
-
- if (menulist[i].name == NULL)
- {
- XtCreateManagedWidget ("separator",
- xmSeparatorWidgetClass,
- menu, args, argcount);
- separators++; /* Count how many entries aren't buttons */
- }
- /*
- * If there is a name and a callback, create a "normal" menu entry and
- * register the callback function.
- */
- else if (menulist[i].func)
- {
- argcount = 0;
- XtSetArg (args[argcount], XmNmnemonic,
- (XtArgVal) menulist[i].key_name);
- argcount++;
-
- buttons[i - separators] = XtCreateWidget (menulist[i].name,
- xmToggleButtonWidgetClass,
- menu, args, argcount);
-
- XtAddCallback (buttons[i - separators], XmNvalueChangedCallback,
- menulist[i].func, menulist[i].data);
-
- if ((strcmp (menulist[i].name, connect_to_server_string) == 0))
- {
- sub_menu_state_list[BUTTON_connect_server] = buttons[i - separators];
- }
- if ((strcmp (menulist[i].name, disconnect_to_server_string) == 0))
- {
- sub_menu_state_list[BUTTON_disconnect_server] = buttons[i - separators];
- }
-
-
- else if ((strcmp (menulist[i].name, font_Default_string) == 0))
- {
- sub_menu_state_list[BUTTON_Default] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, font_6x10_string) == 0))
- {
- sub_menu_state_list[BUTTON_6x10] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, font_6x12_string) == 0))
- {
- sub_menu_state_list[BUTTON_6x12] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, font_6x13_string) == 0))
- {
- sub_menu_state_list[BUTTON_6x13] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, font_8x13_string) == 0))
- {
- sub_menu_state_list[BUTTON_8x13] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, font_9x15_string) == 0))
- {
- sub_menu_state_list[BUTTON_9x15] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, font_ibm10x20_string) == 0))
- {
- sub_menu_state_list[BUTTON_ibm10x20] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, general_help_string) == 0))
- {
- sub_menu_state_list[BUTTON_general_help] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, option_help_string) == 0))
- {
- sub_menu_state_list[BUTTON_options_help] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, known_help_string) == 0))
- {
- sub_menu_state_list[BUTTON_known_help] = buttons[i - separators];
- }
-
-
- else if ((strcmp (menulist[i].name, increase_string1) == 0))
- {
- sub_menu_state_list[BUTTON_button_1_increase] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, decrease_string1) == 0))
- {
- sub_menu_state_list[BUTTON_button_1_decrease] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, popup_string1) == 0))
- {
- sub_menu_state_list[BUTTON_button_1_popup] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, increase_string2) == 0))
- {
- sub_menu_state_list[BUTTON_button_2_increase] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, decrease_string2) == 0))
- {
- sub_menu_state_list[BUTTON_button_2_decrease] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, popup_string2) == 0))
- {
- sub_menu_state_list[BUTTON_button_2_popup] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, increase_string3) == 0))
- {
- sub_menu_state_list[BUTTON_button_3_increase] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, decrease_string3) == 0))
- {
- sub_menu_state_list[BUTTON_button_3_decrease] = buttons[i - separators];
- }
- else if ((strcmp (menulist[i].name, popup_string3) == 0))
- {
- sub_menu_state_list[BUTTON_button_3_popup] = buttons[i - separators];
- }
-
-
-
- }
-
- /*
- * If there is a name, but no callback function, the entry must be a
- * label, unless there is a submenu.
- */
- else if (!menulist[i].sub_menu)
- {
- argcount = 0;
- XtSetArg (args[argcount], XmNmnemonic,
- (XtArgVal) menulist[i].key_name);
- argcount++;
-
- buttons[i - separators] = XtCreateWidget (menulist[i].name,
- xmLabelWidgetClass,
- menu, args, argcount);
-
-
- }
- /*
- * If we got here, the entry must be a submenu. Create a pulldown menu
- * pane and an XmCascadeButton widget. Attach the menu pane and make a
- * recursive call to create the entries in the submenu.
- */
- else
- {
- Widget sub_menu;
- argcount = 0;
- sub_menu = XmCreatePulldownMenu (menu,
- menulist[i].sub_menu_title,
- args, argcount);
-
- argcount = 0;
- XtSetArg (args[argcount], XmNsubMenuId, sub_menu);
- argcount++;
- XtSetArg (args[argcount], XmNmnemonic,
- (XtArgVal) menulist[i].key_name);
- argcount++;
-
- buttons[i - separators] =
- XtCreateWidget (menulist[i].name,
- xmCascadeButtonWidgetClass,
- menu, args, argcount);
-
- if ((strcmp (menulist[i].name, help_string) == 0))
- {
- help_widget = buttons[i - separators];
- }
-
- xs_create_menu_buttons (menulist[i].sub_menu_title,
- sub_menu, menulist[i].sub_menu,
- menulist[i].n_sub_items,
- dynamic_callback_data,
- callback_data);
- }
- }
- /*
- * Manage all button widgets. Menu panes are not managed.
- */
-
- XtManageChildren (buttons, nitems - separators);
-
- argcount = 0;
- XtSetArg (args[argcount], XmNmenuHelpWidget, help_widget);
- argcount++;
- XtSetValues (menu, args, argcount);
- }
-
- void
- create_window_option_menu_bar (title, menu, menulist, nitems, dynamic_callback_data, callback_data,widget_list)
- char *title;
- Widget menu;
- xs_window_menu_struct *menulist;
- int nitems;
- int dynamic_callback_data;
- struct window_button_callback_struct *callback_data;
- Widget *widget_list;
- {
- int i;
- WidgetList buttons;
- int separators = 0;
-
- Arg args[32];
- int argcount = 0;
-
-
- /*
- * Allocate a widget list to hold all button widgets.
- */
-
- buttons = (WidgetList) XtMalloc (nitems * sizeof (Widget));
-
- /*
- * If a title is given, create Label and Separator widgets.
- */
-
- if (title)
- {
-
- argcount = 0;
-
- XtCreateManagedWidget (title, xmLabelWidgetClass, menu,
- args, argcount);
-
- XtCreateManagedWidget ("separator", xmSeparatorWidgetClass,
- menu, args, argcount);
- }
-
- /*
- * Create an entry for each item in the menu.
- */
-
- for (i = 0; i < nitems; i++)
- {
-
- /*
- * A NULL name represents a separator.
- */
-
- if (menulist[i].name == NULL)
- {
- XtCreateManagedWidget ("separator",
- xmSeparatorWidgetClass,
- menu, args, argcount);
- separators++; /* Count how many entries aren't buttons */
- }
- /*
- * If there is a name and a callback, create a "normal" menu entry and
- * register the callback function.
- */
- else if (menulist[i].func)
- {
- /*
- fprintf (stdout, "Got a functions\n");
- */
- argcount = 0;
- XtSetArg (args[argcount], XmNmnemonic,
- (XtArgVal) menulist[i].key_name);
-
- if (menulist[i].indicatorType == 1 )
- {
-
-
- XtSetArg (args[argcount], XmNindicatorType,
- (XtArgVal) XmONE_OF_MANY);
- argcount++;
- XtSetArg (args[argcount], XmNselectColor,
- colorAuxButtonOnBackground.pixel);
- argcount++;
-
-
-
- }
- else
- if (menulist[i].indicatorType == 2 )
- {
- XtSetArg (args[argcount], XmNindicatorType,
- (XtArgVal) XmN_OF_MANY);
- argcount++;
-
- XtSetArg (args[argcount], XmNselectColor,
- colorAuxButtonOnBackground.pixel);
- argcount++;
- }
- else
- {
- XtSetArg (args[argcount], XmNindicatorOn, False);
- argcount++;
- }
-
- XtSetArg (args[argcount], XmNbackground,
- colorAuxButtonOffBackground.pixel);
- argcount++;
- XtSetArg (args[argcount], XmNforeground,
- colorAuxButtonOffForeground.pixel);
- argcount++;
-
- if (menulist[i].state & TOGGLE_STIPPLED )
- {
- XtSetArg (args[argcount], XmNsensitive, False);
- argcount++;
- XtSetArg (args[argcount], XmNset, False);
- argcount++;
- }
-
- if (menulist[i].state & TOGGLE_ON )
- {
- XtSetArg (args[argcount], XmNset, True );
- argcount++;
-
- }
-
- buttons[i - separators] = XtCreateWidget (menulist[i].name,
- xmToggleButtonWidgetClass,
- menu, args, argcount);
- /*
- if (menulist[i].state & TOGGLE_ON)
- {
-
- XmToggleButtonSetState(buttons[i - separators],
- True,
- False);
- }
- */
-
- if (menulist[i].dynamic_data_index != -1)
- {
-
- /*
- * Save the wiget if this is a "VIEW" widget....
- */
- if (menulist[i].dynamic_data_index < dynamic_callback_data)
- {
- /*
- fprintf(stdout,"Saving the VIEW widget %d\n",
- menulist[i].dynamic_data_index);
- */
-
- widget_list[menulist[i].dynamic_data_index] =
- buttons[i - separators];
- }
- /*
- fprintf (stdout, "Going to use dynamic callback at offset %d\n",
- menulist[i].dynamic_data_index);
-
- fprintf (stdout, "sort_mode = %d\n",
- callback_data[menulist[i].dynamic_data_index].sort_mode);
-
- */
- XtAddCallback (buttons[i - separators], XmNvalueChangedCallback,
- menulist[i].func,
- &callback_data[menulist[i].dynamic_data_index]);
-
- }
- else
- XtAddCallback (buttons[i - separators], XmNvalueChangedCallback,
- menulist[i].func, menulist[i].data);
- }
-
- /*
- * If there is a name, but no callback function, the entry must be a
- * label, unless there is a submenu.
- */
- else if (!menulist[i].sub_menu)
- {
- argcount = 0;
- XtSetArg (args[argcount], XmNmnemonic,
- (XtArgVal) menulist[i].key_name);
- argcount++;
- if (menulist[i].state & TOGGLE_ON)
- {
- XtSetArg (args[argcount], XmNbackground,
- colorAuxButtonOnBackground.pixel);
- argcount++;
- XtSetArg (args[argcount], XmNforeground,
- colorAuxButtonOnForeground.pixel);
- argcount++;
- }
- else
- {
- XtSetArg (args[argcount], XmNbackground,
- colorAuxButtonOffBackground.pixel);
- argcount++;
- XtSetArg (args[argcount], XmNforeground,
- colorAuxButtonOffForeground.pixel);
- argcount++;
- }
-
-
- buttons[i - separators] = XtCreateWidget (menulist[i].name,
- xmLabelWidgetClass,
- menu, args, argcount);
-
-
- }
- /*
- * If we got here, the entry must be a submenu. Create a pulldown menu
- * pane and an XmCascadeButton widget. Attach the menu pane and make a
- * recursive call to create the entries in the submenu.
- */
- else
- {
- Widget sub_menu;
- argcount = 0;
-
- /*
- if (menulist[i].state)
- {
- XtSetArg (args[argcount], XmNbackground,
- colorAuxButtonOnBackground.pixel);
- argcount++;
- XtSetArg (args[argcount], XmNforeground,
- colorAuxButtonOnForeground.pixel);
- argcount++;
- }
- else
- {
- XtSetArg (args[argcount], XmNbackground,
- colorAuxButtonOffBackground.pixel);
- argcount++;
- XtSetArg (args[argcount], XmNforeground,
- colorAuxButtonOffForeground.pixel);
- argcount++;
- }
- */
-
- sub_menu = XmCreatePulldownMenu (menu,
- menulist[i].sub_menu_title,
- args, argcount);
-
- argcount = 0;
- XtSetArg (args[argcount], XmNsubMenuId, sub_menu);
- argcount++;
- XtSetArg (args[argcount], XmNmnemonic,
- (XtArgVal) menulist[i].key_name);
- argcount++;
- if (menulist[i].state & TOGGLE_ON)
- {
- XtSetArg (args[argcount], XmNbackground,
- colorAuxButtonOnBackground.pixel);
- argcount++;
- XtSetArg (args[argcount], XmNforeground,
- colorAuxButtonOnForeground.pixel);
- argcount++;
- }
- else
- {
- XtSetArg (args[argcount], XmNbackground,
- colorAuxButtonOffBackground.pixel);
- argcount++;
- XtSetArg (args[argcount], XmNforeground,
- colorAuxButtonOffForeground.pixel);
- argcount++;
- }
-
-
- buttons[i - separators] =
- XtCreateWidget (menulist[i].name,
- xmCascadeButtonWidgetClass,
- menu, args, argcount);
-
- create_window_option_menu_bar (menulist[i].sub_menu_title,
- sub_menu, menulist[i].sub_menu,
- menulist[i].n_sub_items,
- dynamic_callback_data,
- callback_data,
- widget_list);
- }
- }
- /*
- * Manage all button widgets. Menu panes are not managed.
- */
-
- XtManageChildren (buttons, nitems - separators);
-
- }
-